package com.wcsy.myblog.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wcsy.myblog.dao.UserInfoMapper;
import com.wcsy.myblog.dao.UserMapper;
import com.wcsy.myblog.entity.User;
import com.wcsy.myblog.entity.UserInfo;
import com.wcsy.myblog.service.IUserInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements IUserInfoService {
    @Autowired
    UserInfoMapper userInfoMapper;
    @Autowired
    HttpSession session;
    @Autowired
    UserMapper userMapper;

    @Override
    public void insertUserInfo(UserInfo userInfo) {
        User user = (User) session.getAttribute("user");
        userInfo.setUserId(user.getUserId());
        userInfoMapper.insertUserInfo(userInfo);
    }

    @Override
    public void update(UserInfo userInfo) {
       //根据用户id查出出userInfoId
               User user = (User) session.getAttribute("user");
//        User user = userMapper.selectOne(new QueryWrapper<User>().eq("user_id", 1));
        UserInfo userInfo1 = userInfoMapper.selectUserInfo((int) user.getUserId());
        userInfo.setUserInfoId(userInfo1.getUserInfoId());
        userInfoMapper.updateUserInfo(userInfo);
    }
}
